const domainName = getApp().globalData.domainName
const parameter = getApp().globalData.parameter



// pages/chap_doti_rec/chap_doti_rec.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    page_no:0,
    page_size:50,
    no_more:false,
    dotirec_list:[],
  },

  // 查看详情
  view_deteils(e){
    getApp().get_vibration()
    let index = e.currentTarget.id
    let ti_id = this.data.dotirec_list[index].ti_id
    let done_count = this.data.dotirec_list[index].done_count
    wx.navigateTo({
      url: '/pages/students/ti_doti_rec/ti_doti_rec?ti_id=' + ti_id + '&jg_stu_id=' + this.data.jg_stu_id + '&done_count=' + done_count
    })

  },

  // 加载习题列表
  page_init(jg_stu_id,chap_id,page_no,page_size){
    wx.showLoading({
      title: '网络通讯中...',
      mask: false,
    })
    wx.request({
      url: domainName + 'chap_doti_rec_init',
      data: {
        jg_stu_id:jg_stu_id || '',
        chap_id:chap_id,
        page_no:page_no,
        page_size:page_size,
      },...parameter,
      success: res => {
        // console.log('res',res.data)
        wx.hideLoading()
        var dotirec_list = res.data.dotirec_list
        if(dotirec_list.length>0){
          this.setData({
            dotirec_list: this.data.dotirec_list.concat(dotirec_list),
            page_no:this.data.page_no + 1,
          })
        }else{
          this.setData({
            no_more:true
          })
        }
      },
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log('options',options)
    this.setData({
      chap_id:options.chap_id,
      jg_stu_id:options.jg_stu_id,
      stu_name:options.stu_name,
    })
    
    wx.setNavigationBarTitle({
      title: options.stu_name + '【' + options.chap_name + '】',
    })
    
    this.page_init(this.data.jg_stu_id, this.data.chap_id,this.data.page_no,this.data.page_size)
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if(!this.data.no_more){
      this.page_init(this.data.jg_stu_id, this.data.chap_id,this.data.page_no,this.data.page_size)
    }
  },

})